import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Rectangle {
    id: __func_bar

    signal sigCopy()
    property Image _image: null

    color: "#30FFFFFF"

    function fillShow()
    {
        if(_image === null)
            return
        var w = _image.sourceSize.width
        var h = _image.sourceSize.height
        var angle = _image.rotation
        if(angle === 90 || angle === 270)
        {
            var tmp = w
            w = h
            h = tmp
        }

        var ratioW = (__func_bar.parent.width - 20) / w
        var ratioH = (__func_bar.parent.height - 20) / h
        var ratio = Math.min(ratioW , ratioH)
        if(ratio > 1.00)
            ratio = 1.0
        _image.scale = ratio.toFixed(2)
    }

    RowLayout {
        anchors.centerIn: parent
        spacing: 8
        Button {
            text: "放大"
            onClicked: {
                if(_image === null)
                    return
                _image.scale = _image.scale * 1.20
            }
        }
        Button {
            text: "缩小"
            onClicked: {
                if(_image === null)
                    return
                _image.scale = _image.scale / 1.20
            }
        }
        Button {
            text: "原图"
            onClicked: {
                if(_image === null)
                    return
                _image.scale = 1.0
            }
        }
        Button {
            text: "适应"
            onClicked: {
                fillShow()
            }
        }
        Button {
            text: "旋转"
            onClicked: {
                if(_image === null)
                    return
                var angle = _image.rotation + 90
                if(angle >= 360)
                    angle = 0
                _image.rotation = angle
            }
        }
        Button {
            text: "另存为"
            onClicked: {
                if(_image.source === "" || _image.status !== Image.Ready)
                    return
                sigCopy()

            }
        }
    }
}
